﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Controllers;
using System.Configuration;

namespace Web
{
    public partial class Specail : System.Web.UI.Page
    {
        ApolloOaDataContext ctx = new ApolloOaDataContext(ConfigurationManager.ConnectionStrings["SqlConnectionString"].ConnectionString);
        protected void Page_Load(object sender, EventArgs e)
        {
            EmpBasicInfo ebi = Session["ebi"] as EmpBasicInfo;
            if (!IsPostBack)
                bind();
        }

        protected void btnSub_Click(object sender, EventArgs e)
        {
            //添加 
            WorkOrRest model = new WorkOrRest();
            model.SpecialDate = DateTime.Parse(speDate.Value);
            if (chkIsWork.Checked)
                model.IsWork = 1;
            else
                model.IsWork = 0;
            ctx.WorkOrRest.InsertOnSubmit(model);
            ctx.SubmitChanges();
            bind();
        }

        private void bind()
        {
            gv.DataSource = ctx.WorkOrRest.OrderByDescending(q => q.SpecialDate);
            gv.DataBind();
        }

        protected void gv_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {
            gv.PageIndex = e.NewPageIndex;
            bind();
        }

        protected void lbtnDel_Click(object sender, CommandEventArgs e)
        {
            IEnumerable<WorkOrRest> model = ctx.WorkOrRest.Where(q => q.id == int.Parse(e.CommandArgument.ToString()));
            ctx.WorkOrRest.DeleteAllOnSubmit(model);
            ctx.SubmitChanges();
            bind();
        }
    }
}